package com.interagriculture.common;

import com.interagriculture.enums.GlobalStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

/**
 * @author 10 2024/10/23
 */
@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public  static <T>Result<T> build(Integer code,String message,T data){
         Result result = new Result();
         result.setData(data);
         result.setCode(code);
         result.setMessage(message);
         return  result;
    }
    public static <T>Result<T> build(T data){
         Result<T> result = new Result<>();
         result.setData(data);
         return  result;
    }
    public static <T>Result<T> build(T data, GlobalStatusEnum statusEnum){
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(statusEnum.getCode());
        result.setMessage(statusEnum.getDesc());
        return  result;
    }

    public static <T>Result<T> ok(){
        Result result = Result.build(null, GlobalStatusEnum.REQUEST_SUCCESS);
        return result;
    }
    public static <T>Result<T> ok(T data){
        Result<T> result = Result.ok();
        result.setData(data);
        return result;
    }
    public static Result fail(GlobalStatusEnum statusEnum){
        Result result = new Result();
        result.setCode(statusEnum.getCode());
        result.setMessage(statusEnum.getDesc());
        return result;
    }

}
